<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="custom" tagdir="/WEB-INF/tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Konto użytkownika</title>
	<script type="text/javascript">
		function save() {
			$('span[id^="error_"]').html('');
			$("#restaurantForm").spin();
			$.ajax({
				type : "POST",
				url : '/saveRestaurant',
				data : $("#restaurantForm").serialize(),
				success : function(response) {
					$("#restaurantForm").spin(false);
					if (response.status == "FAILURE") {
						for (i = 0; i < response.errorMessageList.length; i++) {
							var item = response.errorMessageList[i];
							$("#restaurantForm"+" span[id='error_" + response.errorMessageList[i].fieldName+"']").html(
									response.errorMessageList[i].message);
						}
						$.gritter.add({
							title: response.result.title,
							text: response.result.content
						});
					}
					else {
						$.gritter.add({
							title: response.result.title,
							text: response.result.content
						});
						setTimeout(function(){ location.reload(); }, 2000);
					}
				},
				error : function(e) {
					alert(e);
				}
			});
		}
	</script>
	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
	<script type="text/javascript" src="/scripts/gmaps.js"></script>
	<script type="text/javascript" src="/scripts/prettify.js"></script>
	<link href='/css/prettify.css' rel='stylesheet' type='text/css' />
	<link href='/css/gmaps.styles.css' rel='stylesheet' type='text/css' />
	<link href='/css/quickAccess.css' rel='stylesheet' type='text/css' />
	<script type="text/javascript" src="/scripts/quickAccess.js"></script>

	<script type="text/javascript">
	    var map;
	    $(document).ready(function(){
	    	var qaccess = $('#meeenu').quickAccess({
	    		screenPosition: 'left',
	    		width: '150px',
	    		css: {position: 'fixed'},
	    		itemCss: {
	    			'backgroundColor': '#893c40', 
	    			'borderWidth': 1, 
	    			'borderColor': '#ccc', 
	    			'borderStyle': 'solid'
	    		},
	    		margin: '0px', 
	    		radius: { 
	    			borderTopLeftRadius: '0px', 
	    			borderTopRightRadius: '8px', 
	    			borderBottomLeftRadius: '0px', 
	    			borderBottomRightRadius: '8px'
	    		}
	    	});
	      prettyPrint();
	      map = new GMaps({
	        div: '#map',
	        lat: ${restaurantForm.restaurant.latitude},
	        lng: ${restaurantForm.restaurant.longitude}
	      });
	      
	      map.addMarker({
	          lat: ${restaurantForm.restaurant.latitude},
	          lng: ${restaurantForm.restaurant.longitude},
	          title: 'Marker with InfoWindow',
	          infoWindow: {
	            content: '<p>HTML Content</p>'
	          }
	        });
	    });
	 </script>
</head>
<body>
	<div id="content">
	<jsp:include page="accountMenu.jsp"/>
	<h3>Twoja restauracja</h3>
		<br />
		<form:form method="POST"  commandName="restaurantForm" >
			<custom:inputText label="Nazwa" name="restaurant.name"/>
			<custom:inputTextArea label="Opis" name="restaurant.description"/>
			<custom:inputText label="Pełny adres" name="restaurant.address"/>
			<custom:inputText label="Adres www" name="restaurant.wwwSite"/>
			<c:if test="${restaurantForm.restaurant.id > 0 }">
				<custom:button onclick="save()" value="Zapisz"/>
			</c:if>
			<c:if test="${restaurantForm.restaurant.id == 0 }">
				<custom:button onclick="save()" value="Dodaj restauracje"/>
			</c:if>
		</form:form>
		
	</div>
	<div id="sidePanel">
		<h3>Lokalizacja:</h3>
		<br/>
		<c:if test="${restaurantForm.restaurant.id > 0 }">
			<div class="popin">
				<div id="map"></div>
			</div>
		</c:if>
		<c:if test="${restaurantForm.restaurant.id == 0 }">
			Lokalizacja restauracji dostepna jest jedynie po dodaniu jej do bazy.
		</c:if>
	</div>
	
</body>
</html>